package com.aote.expression.paramprocessor;

import java.util.Map;

import com.aote.component.SQLComponent;
import com.aote.expression.Param;
import com.aote.util.ComponentHelper;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.user.User;

/**
 * 从SQL组件执行结果中取需要的值
 */
public class SQLValueProcessor implements ParamProcessor {
	public String process(Param param, Map attribures, User loginUser,
			HTMLBasicComponent component) {
		// 要取值的名称
		String name = (String) param.getParams().get("condition");
		SQLComponent scomp = (SQLComponent) ComponentHelper.getChildComponent(
				component, SQLComponent.class);
		String result = "";
		try {
			result = scomp.getValue(name);
		} catch (Exception e) {
			result = "";
		}
		// 如果没有type参数,说明是数字,空值转换成0
		String type = (String) param.getParams().get("type");
		if (type == null && result.trim().equals("") || result.equals("　")) {
			result = "0";
		}
		return result;
	}
}
